package com.mayqlzu.scrollviewevent;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ListView;

/**
 * Created by wangbh on 2017/10/18.
 */

public class MyListView extends ListView {
    private final static String TAG="MyListViews";
    public MyListView(Context context) {
        super(context);
        Log.d(TAG, "MyListView: 初始化1");
    }

    public MyListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        Log.d(TAG, "MyListView: 初始化2");
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int newHeightMeasureSpec = MeasureSpec.makeMeasureSpec(680, // 固定高度（实际中这个值应该是根据手机屏幕计算出来的）
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, newHeightMeasureSpec);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        boolean b = super.dispatchTouchEvent(ev);
       // Log.d(TAG, "dispatchTouchEvent: "+b);
        return b;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        boolean b = super.onInterceptTouchEvent(ev);
       // Log.d(TAG, "onInterceptTouchEvent: "+b);
        return b;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d(TAG, "MyListView ACTION_DOWN: ");
                break;
            case MotionEvent.ACTION_MOVE:
              //  ViewParent parent = getParent();
                getParent().requestDisallowInterceptTouchEvent(true);
                Log.d(TAG, "MyListView ACTION_MOVE: ");
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG, "MyListView ACTION_UP: ");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d(TAG, "MyListView ACTION_CANCEL: ");
                getParent().requestDisallowInterceptTouchEvent(false);
                break;

        }

        boolean b = super.onTouchEvent(ev);
        //Log.d(TAG, "onTouchEvent: "+b);
        return b;
    }
}
